package com.pet.seller.controller;

import com.pet.seller.mapper.OrdersMapper;
import com.pet.seller.model.Orders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;


@RestController
public class OrdersController {
    @Autowired
    private OrdersMapper ordersMapper;

    @RequestMapping(value="/finishOrders",method = RequestMethod.POST)
    public String finishOrders(HttpServletRequest request, Model model) throws ParseException {
        String id = request.getParameter("id");
        Orders orders = ordersMapper.selectByPrimaryKey(Integer.parseInt(id));
        orders.setStatus("FINISHED");
        ordersMapper.updateByPrimaryKeySelective(orders);
        return "OK";
    }

}